<!DOCTYPE html>
<html>
 <head> 
  <title>小i机器人微信自动回复代码测试--闫海的个人博客-芒果小叨</title> 
  <!-- meta tags start --> 
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
  <meta name="Keywords" content="个人博客,闫海个人博客,小i机器人,微信自动回复,微信代码,小i,小i测试" /> 
  <meta name="Description" content="自己写的一段小i机器人微信自动回复代码测试." /> 
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> 
  <!-- meta tags end -->
  <!-- favorite icon starts -->
  <link rel="shortcut icon" href="/Public/Index/mobile/images/common/favicon.ico" type="image/x-icon" />
  <!-- favorite icon ends -->
  <!-- CSS files start -->
  <link href="/Public/Index/mobile/css/framework.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/Public/Index/mobile/css/colorbox.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/Public/Index/mobile/css/responsive.css" rel="stylesheet" type="text/css" media="screen" />
  <link href="/Public/Index/mobile/css/hidpi.css" rel="stylesheet" type="text/css" media="screen" />
  <link href="/Public/Index/mobile/css/skin.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/Public/Index/mobile/css/custom.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/Public/Index/mobile/css/elements.css" rel="stylesheet" type="text/css" media="all" />
  <link href="/Public/Index/mobile/css/style.css" rel="stylesheet" type="text/css" media="all" />
  
  <!-- CSS files end -->
  <!-- JavaScript files start --> 
  <script type="text/javascript" src="/Public/Index/mobile/grayscale.js"></script>
  <script type="text/javascript" src="/Public/Index/mobile/js/jquery.min.js"></script>
  <script type="text/javascript" src="/Public/Index/mobile/js/effects.jquery-ui.min.js"></script>
  <script type="text/javascript" src="/Public/Index/mobile/js/jquery.nivo-slider.min.js"></script>
  <script type="text/javascript" src="/Public/Index/mobile/js/custom.js"></script>
  <script type="text/javascript" src="/Public/Index/mobile/js/jquery.colorbox.min.js"></script>
  
  <!-- JavaScript files end -->
 </head>
 <body>
  <!-- website wrapper starts -->
  <div class="websiteWrapper"> 
   <!-- main menu wrapper starts --> 
   <div class="mainMenuOuterWrapper"> 
    <a href="#" class="mainMenuCloseButton"></a> 
    <ul class="mainMenuWrapper"> 
     <li class="currentPage"><a href='/mobile.php/index.html' title='首页'>首页</a></li>
      <li><a href='/mobile.php/list/2.html' title='关于我'>关于我<span> </span></a></li><li><a href='/mobile.php/list/3.html' title='时光轴'>时光轴<span> </span></a></li><li><a href='/mobile.php/list/1.html' title='品味人生'>品味人生<span> </span></a></li><li><a href='/mobile.php/list/5.html' title='技术分享'>技术分享<span> </span></a></li>     <li><a href='/mobile.php/index/article/message.html'  title='给我留言'>给我留言</a></li>
    </ul> 
   </div> 
   <!-- main menu wrapper ends --> 

<script type="text/javascript">
  var url = '/mobile.php/article';
  $(function(){
    var id = '35';
    $.post(url+'/addClick',{'id':id},function(data){
        $("#pclick").html('点击数：' + data);
    });
  })
</script>
   <!-- header wrapper starts --> 
   <div class="headerOuterWrapper pageHeaderWrapper"> 
    <div class="headerWrapper"> 
     <a class="mainLogo" href="/mobile.php/index.html"><img src="/Public/Index/mobile/images/mainLogo.png" alt="" /></a> 
     <a href="#" class="mainMenuButton"></a>
    </div>
    <!-- page title starts --> 
    <h5 class="pageTitle">当前位置：
	<a href="/mobile.php/index.html">首页</a>&nbsp;&gt;&nbsp;
	<a href="/mobile.php/list/5.html">技术分享</a>
	&nbsp;&gt;&nbsp;<a href="/mobile.php/list/10.html">php</a>
	</h5>    <!-- page title ends --> 
   </div>
   <!-- header wrapper ends --> 
   <!-- page wrapper starts --> 
   <div class="pageWrapper singlePostPageWrapper"> 
    <!-- post content wrapper starts --> 
    <div class="singlePostContentWrapper">
    <h3 class="pageTitle" style="background:#F0F0F0;color:#333;text-align:center;">小i机器人微信自动回复代码测试</h3> 
     <div class="pageSpacer"></div> 
     <div class="pageSpacer"></div> 
     <div style="word-break: break-all;" class="phoneContent"><p>自己写的，测试可用，仅展示部分关键代码，希望对大家有所帮助。</p><pre class="brush:php;toolbar:false">&lt;?php
/**
&nbsp;*&nbsp;....此处省略
&nbsp;*&nbsp;
**/
if($msgType&nbsp;==&nbsp;&#39;text&#39;){
&nbsp;&nbsp;&nbsp;&nbsp;//判断用户纯递过来的文本消息是否为空
&nbsp;&nbsp;&nbsp;&nbsp;if(!empty(&nbsp;$keyword&nbsp;))
&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//生成签名及加密算法
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$app_key=&quot;填写你的AppID&nbsp;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$app_secret=&quot;填写你的AppSecret(应用密钥)&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$realm&nbsp;=&nbsp;&quot;xiaoi.com&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$method&nbsp;=&nbsp;&quot;POST&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$uri&nbsp;=&nbsp;&quot;/robot/ask.do&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nonce=&quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$chars&nbsp;=&nbsp;&quot;abcdefghijklmnopqrstuvwxyz0123456789&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(&nbsp;$i&nbsp;=&nbsp;0;&nbsp;$i&nbsp;&lt;&nbsp;40;&nbsp;$i++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$nonce&nbsp;.=&nbsp;$chars[&nbsp;mt_rand(0,&nbsp;strlen($chars)&nbsp;-&nbsp;1)&nbsp;];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$HA1&nbsp;=&nbsp;sha1($app_key&nbsp;.&nbsp;&quot;:&quot;&nbsp;.&nbsp;$realm&nbsp;.&nbsp;&quot;:&quot;&nbsp;.&nbsp;$app_secret);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$HA2&nbsp;=&nbsp;sha1($method&nbsp;.&nbsp;&quot;:&quot;&nbsp;.&nbsp;$uri);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$sign&nbsp;=&nbsp;sha1($HA1&nbsp;.&nbsp;&quot;:&quot;&nbsp;.&nbsp;$nonce&nbsp;.&nbsp;&quot;:&quot;&nbsp;.&nbsp;$HA2);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header(&#39;Content-type:text/html;charset=utf-8&#39;);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$url&nbsp;=&nbsp;&quot;http://nlp.xiaoi.com/robot/ask.do&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//初始化curl
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$go&nbsp;=&nbsp;curl_init();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置参数(1初始化，2设置常量)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($go,&nbsp;CURLOPT_URL,&nbsp;$url);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置请求url网址
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($go,&nbsp;CURLOPT_RETURNTRANSFER,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;//响应数据不输出
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($go,&nbsp;CURLOPT_HEADER,&nbsp;0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置请求头信息
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($go,&nbsp;CURLOPT_POST,&nbsp;1);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//设置开启POST
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($go,&nbsp;CURLOPT_POSTFIELDS,&nbsp;&quot;question=&quot;.urlencode($keyword).&quot;&amp;userId=&quot;.$toUsername.&quot;&amp;type=1&quot;);&nbsp;&nbsp;&nbsp;&nbsp;//传输参数值
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//执行curl
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$output&nbsp;=&nbsp;curl_exec($go);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;($output&nbsp;===&nbsp;FALSE){
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;&quot;cURL&nbsp;Error:&nbsp;&quot;.&nbsp;curl_error($go);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//关闭句柄
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_close($go);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//定义返回消息类型（text文本）
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$msgType&nbsp;=&nbsp;&quot;text&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//返回相应回复
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$contentStr&nbsp;=&nbsp;$output;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//sprintf把字符串按照指定模式进行格式化%s
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//（格式化字符串，格式化变量）
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$resultStr&nbsp;=&nbsp;sprintf($textTpl,&nbsp;$fromUsername,&nbsp;$toUsername,&nbsp;$time,&nbsp;$msgType,&nbsp;$contentStr);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;$resultStr;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;}else{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;&quot;Input&nbsp;something...&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre><p><br/></p></div>
     <div class="textBreak"></div> 
    </div> 
    <!-- post content wrapper ends --> 
    <!-- post info starts --> 
    <div class="singlePostInfoWrapper">
     <span class="singleIconWrapper singleIconText iconCalendarDark postInfo postDate">2015-03-02</span>
     <a class="singleIconWrapper singleIconText iconEditDark postInfo postAuthor postInfoNoMargin">小叨</a>&nbsp;&nbsp;
     <span class="singleIconWrapper singleIconText iconArrowRightDark" id="pclick">点击数：153</span>
    </div> 
    <!-- post info ends --> 
    <!-- post links wrapper starts --> 
    <div class="singlePostContentWrapper"> 
     <p>上一篇：<a href="/mobile.php/article/26.html">php端验证</a></p>
     <p>下一篇：<a href="/mobile.php/article/44.html">写了一个PHP框架</a></p>
    </div> 
    <!-- post links wrapper ends --> 
    <!-- comments section wrapper starts --> 
    <div class="commentsSectionWrapper"> 
     <h4 class="commentsTitle">相关阅读：</h4> 
     <!-- comments wrapper starts --> 
     <!-- accordion item wrapper starts --> 
        <div class="accordionContent"> 
         <p><a href="/mobile.php/article/44.html" title="写了一个PHP框架">写了一个PHP框架</a></p><p><a href="/mobile.php/article/35.html" title="小i机器人微信自动回复代码测试">小i机器人微信自动回复代码测试</a></p><p><a href="/mobile.php/article/26.html" title="php端验证">php端验证</a></p><p><a href="/mobile.php/article/25.html" title="自定义模板引擎的基本原理">自定义模板引擎的基本原理</a></p><p><a href="/mobile.php/article/23.html" title="图像处理类（缩略图，裁剪，打水印）">图像处理类（缩略图，裁剪，打水印）</a></p><p><a href="/mobile.php/article/19.html" title="验证码类(练手)">验证码类(练手)</a></p>        </div> 
     <!-- accordion item wrapper ends -->
     <!-- coments wrapper ends --> 
    </div> 
    <!-- comments section wrapper ends --> 
   </div> 
   <!-- page wrapper ends --> 
   <!-- footer wrapper starts --> 
   <div class="footerWrapper"> 
    <!-- copyright wrapper starts --> 
    <div class="copyrightWrapper"> 
     <!-- copyright starts --> 
     <span class="copyright"><a href="http://www.miitbeian.gov.cn/">鲁ICP备15004472号-1</a></span> 
     <!-- copyright ends --> 
     <!-- back to top button starts --> 
     <a href="" class="backToTopButton"></a> 
     <!-- back to top button ends --> 
    </div> 
    <!-- copyright wrapper ends --> 
   </div> 
   <!-- footer wrapper ends --> 
  </div>
  <!-- website wrapper ends -->
 </body>
</html>